// Open Street Map 地图层
var openStreetMapLayer = new ol.layer.Tile({
    source: new ol.source.OSM()
});

// Bing地图层
var bingMapLayer = new ol.layer.Tile({
    source: new ol.source.BingMaps({
        key: 'AkjzA7OhS4MIBjutL21bkAop7dc41HSE0CNTR5c6HJy8JKc7U9U9RveWJrylD3XJ',
        imagerySet: 'Road'
    })
});
// 高德卫星(有偏移)
var LayerGaodeImg = new ol.layer.Tile({
    source: new ol.source.XYZ({
        // projection: 'EPSG:3857',
        fromProject: "EPSG:900913",
        toProject: "EPSG:4326",
        url: 'http://webst0{1-4}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}'
    })
});
// 高德标注(有偏移)
var LayerGaodeBiaozhu = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'https://wprd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=8&ltype=11'
    })
});
// 百度卫星(有偏移)
var LayerBaiduImg = new ol.layer.Tile({
    source: new ol.source.XYZ({
        // url: 'http://shangetu{0-3}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46&udt=20180721',
        url: 'https://ss{0-3}.bdstatic.com/8bo_dTSlR1gBo1vgoIiO_jowehsv/starpic/?qt=satepc&u=x={x};y={y};z={z};v=009;type=sate&fm=46&app=webearth2&v=009&udt=20180721',
    })
});
// 谷歌卫星图
var LayerGoogleImg = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://khm{0-3}.googleapis.com/kh?v=847&hl=zh-CN&?&x={x}&y={y}&z={z}'
    })
});
// 天地图卫星
var LayerTiandiImg = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://t{0-7}.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}'
    })
});
// 天地图标注
var LayerTiandibiaozhu = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'https://t{0-7}.tianditu.gov.cn/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=2ce94f67e58faa24beb7cb8a09780552'
        //url: 'https://t{0-7}.tianditu.gov.cn/DataServer?T=cia_w&x={x}&y={y}&l={z}'
        //https://t5.tianditu.gov.cn/DataServer?T=cva_w&x=26&y=13&l=5&tk=2ce94f67e58faa24beb7cb8a09780552
    })
});
// ditu.city8.com卫星
var LayerCity8img = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://shangetu{0-4}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46&udt=20180724'
    })
});
// ditu.city8.com标注
var LayerCity8biaozhu = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://online{0-4}.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&styles=sl&udt=20180724'
    })
});

var LayerWeifang = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://122.4.252.56:8399/arcgis/rest/services/hrbuss/MapServer/tile/{z}/{y}/{x}.png'
    })
});
var Layerjiangxi = new ol.layer.Tile({
    source: new ol.source.TileArcGISRest({
        url: 'http://220.175.6.119:8399/arcgis/rest/services/jx_buss20161130/MapServer'
    })
})
///////////////////////////////////////////////////////////////////////潍坊地图
//以下两个参数，通过GeoServer，查看图层属性可获取  
var projection = ol.proj.get('EPSG:4326');
var bounds = [-74.0118315772888, 40.70754683896324, -74.00153046439813, 40.719885123828675];

var vectorSource = new ol.source.Vector({
    //1.通过GeoServer生成的KML文件，保存到此网页文件所在的目录  
    //2.也可以直接使用生成这个文件的链接，动态生成数据文件  
    url: TMPL + 'Weigis/jiangxi.kml',
    format: new ol.format.KML()
});
var vectorLayer = new ol.layer.Vector({
    source: vectorSource
});
//////////////////////////////////////////////////////////////////////////潍坊地图
////////////////////////////////////////////////////////////////////////百度地图有偏移
var projection = ol.proj.get("EPSG:3857");
var resolutions = [];
for (var i = 0; i < 19; i++) {
    resolutions[i] = Math.pow(2, 18 - i);
}
var tilegrid = new ol.tilegrid.TileGrid({
    origin: [0, 0],
    resolutions: resolutions
});

var baiduSource = new ol.source.TileImage({
    projection: projection,
    tileGrid: tilegrid,
    tileUrlFunction: function(tileCoord, pixelRatio, proj) {
        if (!tileCoord) {
            return "";
        }
        var z = tileCoord[0];
        var x = tileCoord[1];
        var y = tileCoord[2];

        if (x < 0) {
            x = "M" + (-x);
        }
        if (y < 0) {
            y = "M" + (-y);
        }

        return "http://online3.map.bdimg.com/onlinelabel/?qt=tile&x=" + x + "&y=" + y + "&z=" + z + "&styles=pl&scaler=1&p=1";
    }
});

// 百度地图层
var baiduMapLayer2 = new ol.layer.Tile({
    source: baiduSource
});